﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Geometry;
using GDCal.vo;
using GDCal.dao;
using System.Collections;
using System.Globalization;
using System.Drawing.Drawing2D;

namespace GDCal
{
    public partial class LandStreetPriceListDetailForm : GDBaseForm
    {
        public LandStreetPriceListDetailForm(Int32 citylandPriceId)
        {
            InitializeComponent();
            LandStreetPriceDetailVO lspdFilterObj = new LandStreetPriceDetailVO();
            lspdFilterObj.setClpId(citylandPriceId);
            ArrayList ret = LandStreetPriceDetailDao.filter(lspdFilterObj);
            if (ret.Count > 0)
            {
                int i = 1;
                foreach (LandStreetPriceDetailVO vo in ret)
                {
                    String[] items = new String[8] { Convert.ToString(i++), vo.getLandIdentify(), vo.getLandCodeDescription(), 
                            vo.getStreetIdentify(), vo.getStreetName(), 
                            vo.getLandArea().ToString("N", CultureInfo.CurrentCulture), 
                            vo.getMinPrice().ToString("N", CultureInfo.CurrentCulture), 
                            vo.getMaxPrice().ToString("N", CultureInfo.CurrentCulture)};
                    ListViewItem item = new ListViewItem(items);
                    if (vo.getMaxPrice() > vo.getMinPrice())
                    {
                        item.BackColor = Color.Blue;
                    }
                    landAreaListView.Items.Add(item);
                }
            }
        }

        private void landAreaListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            TextFormatFlags flags = TextFormatFlags.Left;
            Rectangle rec = new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 4, e.Bounds.Height - 4);

            if (e.ColumnIndex >= 4)
            {
                flags = TextFormatFlags.Right;
            }

            TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.Item.ListView.Font, rec, e.SubItem.ForeColor, flags);
        }

        private void landAreaListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            e.DrawDefault = true;
            e.DrawBackground();
            e.DrawText();
        }

        private void landAreaListView_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            if (Convert.ToDouble(e.Item.SubItems[6].Text) < Convert.ToDouble(e.Item.SubItems[7].Text))
            {
                e.Item.BackColor = Color.RoyalBlue;
                e.DrawBackground();
            }
        }
    }
}
